import OSS from 'ali-oss'
import { REGION, BUCKET } from '@/constants'
import { getSts } from '@/api/sys.js'
export const getOssClient = async (sts) => {
  const res = await getSts()
  return new OSS({
    region: REGION,
    bucket: BUCKET,
    accessKeyId: res.Credentials.AccessKeyId,
    accessKeySecret: res.Credentials.AccessKeySecret,
    stsToken: res.Credentials.SecurityToken,
    refreshSTSToken: async () => {
      const res = await getSts()
      return {
        accessKeyId: res.Credentials.accessKeyId,
        accessKeySecret: res.Credentials.accessKeySecret,
        stsToken: res.Credentials.securityToken
      }
    },
    refreshSTSTokenInterval: 5 * 1000
  })
}
